layui.config({
    base: CXL.ctxPath + '/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index', 'table', 'laydate', 'form', 'layer', 'element'], function () {
    var admin = layui.admin;
    var table = layui.table;
    var laydate = layui.laydate;
    var $ = layui.$;
    var form = layui.form;
    let element = layui.element;
    let router = layui.router();


    initPage();

    function initPage() {
        getCraneStatus(1);
        getCraneStatus(2);
        getCraneStatus(3);
        getCraneStatus(4);
        // console.log(1);
    }

    function getCraneStatus(craneId) {
        // console.log("getFata");
        $.ajax({
            url: CXL.ctxPath + "/configSetting/getCraneWorkStatus",
            data: {craneId: craneId},
            type: "POST",
            dataType: "json",
            success: function (res) {
                if (res.success) {
                    // console.log(11);
                    initCard(craneId,res);
                } else {
                    CXL.error(res.msg);
                }
            },
            fail: function () {
                CXL.error("网络错误！");
            }
        });
    }

    function initCard(craneId,res){
        let data = res.obj;
        form.val("form"+craneId, data);
    }
    //提交表单
    form.on('submit(submitInfo)', function(data){
        // console.log(data.field);
        let crane = data.field.craneId;
        $.ajax({
            url: CXL.ctxPath + "/configSetting/saveConfig",
            data: data.field,
            type: "POST",
            dataType: "json",
            success: function (res) {
                if (res.success) {
                    CXL.info(res.msg);
                    getCraneStatus(Number(crane));
                } else {
                    CXL.error(res.msg);
                }
            },
            fail: function () {
                CXL.error("网络错误！");
            }
        });
    });


});
